package com.ruoyi.apps.service.impl;

import java.util.List;
import java.util.ArrayList;
import com.ruoyi.common.core.domain.Ztree;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.apps.mapper.AntAppsCategoryMapper;
import com.ruoyi.apps.domain.AntAppsCategory;
import com.ruoyi.apps.service.IAntAppsCategoryService;
import com.ruoyi.common.core.text.Convert;

/**
 * 应用分类Service业务层处理
 * 
 * @author lzh
 * @date 2023-01-15
 */
@Service
public class AntAppsCategoryServiceImpl implements IAntAppsCategoryService 
{
    @Autowired
    private AntAppsCategoryMapper antAppsCategoryMapper;

    /**
     * 查询应用分类
     * 
     * @param id 应用分类主键
     * @return 应用分类
     */
    @Override
    public AntAppsCategory selectAntAppsCategoryById(Long id)
    {
        return antAppsCategoryMapper.selectAntAppsCategoryById(id);
    }

    /**
     * 查询应用分类列表
     * 
     * @param antAppsCategory 应用分类
     * @return 应用分类
     */
    @Override
    public List<AntAppsCategory> selectAntAppsCategoryList(AntAppsCategory antAppsCategory)
    {
        return antAppsCategoryMapper.selectAntAppsCategoryList(antAppsCategory);
    }

    /**
     * 新增应用分类
     * 
     * @param antAppsCategory 应用分类
     * @return 结果
     */
    @Override
    public int insertAntAppsCategory(AntAppsCategory antAppsCategory)
    {
        return antAppsCategoryMapper.insertAntAppsCategory(antAppsCategory);
    }

    /**
     * 修改应用分类
     * 
     * @param antAppsCategory 应用分类
     * @return 结果
     */
    @Override
    public int updateAntAppsCategory(AntAppsCategory antAppsCategory)
    {
        return antAppsCategoryMapper.updateAntAppsCategory(antAppsCategory);
    }

    /**
     * 批量删除应用分类
     * 
     * @param ids 需要删除的应用分类主键
     * @return 结果
     */
    @Override
    public int deleteAntAppsCategoryByIds(String ids)
    {
        return antAppsCategoryMapper.deleteAntAppsCategoryByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除应用分类信息
     * 
     * @param id 应用分类主键
     * @return 结果
     */
    @Override
    public int deleteAntAppsCategoryById(Long id)
    {
        return antAppsCategoryMapper.deleteAntAppsCategoryById(id);
    }

    /**
     * 查询应用分类树列表
     * 
     * @return 所有应用分类信息
     */
    @Override
    public List<Ztree> selectAntAppsCategoryTree()
    {
        List<AntAppsCategory> antAppsCategoryList = antAppsCategoryMapper.selectAntAppsCategoryList(new AntAppsCategory());
        List<Ztree> ztrees = new ArrayList<Ztree>();
        for (AntAppsCategory antAppsCategory : antAppsCategoryList)
        {
            Ztree ztree = new Ztree();
            ztree.setId(antAppsCategory.getId());
            ztree.setpId(antAppsCategory.getParentId());
            ztree.setName(antAppsCategory.getName());
            ztree.setTitle(antAppsCategory.getName());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}
